package com.oa.ylms.apps.business.archives.impl;

import java.util.List;

import com.oa.ylms.apps.business.archives.IMajorInfoService;
import com.oa.ylms.apps.constants.IDEDStates;
import com.oa.ylms.apps.dao.archives.IMajorInfoDao;
import com.oa.ylms.apps.entity.archives.MajorInfoValue;

public class MajorInfoServiceImpl implements IMajorInfoService {
	private MajorInfoValue majorInfo;
	private IMajorInfoDao infoDao;

	@Override
	public int addMajorInfo(String majorName) throws Exception {
		majorInfo.setMajorName(majorName);
		majorInfo.setStates(IDEDStates.ENABLE);
		return infoDao.addMajorInfo(majorInfo);
	}

	@Override
	public boolean deleteMajorInfo(int majorId) throws Exception {
		majorInfo = queryByMajorId(majorId);
		if(majorInfo != null){
			majorInfo.setStates(IDEDStates.DELETE);
			return infoDao.editMajorInfo(majorInfo);
		}
		return false;
	}

	@Override
	public boolean modifyMajorInfo(int majorId, String majorName)
			throws Exception {
		majorInfo = queryByMajorId(majorId);
		if(majorInfo != null){
			majorInfo.setMajorName(majorName);
			return infoDao.editMajorInfo(majorInfo);
		}
		return false;
	}

	@Override
	public List<MajorInfoValue> queryALLMajorInfo() throws Exception {
		return infoDao.queryALLMajorInfo();
	}

	@Override
	public MajorInfoValue queryByMajorId(int majorId) throws Exception {
		majorInfo.setMajorId(majorId);
		return infoDao.queryByMajorId(majorInfo);
	}

	@Override
	public boolean toDisable(int majorId) throws Exception {
		majorInfo = queryByMajorId(majorId);
		if(majorInfo != null){
			majorInfo.setStates(IDEDStates.DISABLE);
			return infoDao.editMajorInfo(majorInfo);
		}
		return false;
	}

	@Override
	public boolean toEnable(int majorId) throws Exception {
		majorInfo = queryByMajorId(majorId);
		if(majorInfo != null){
			majorInfo.setStates(IDEDStates.ENABLE);
			return infoDao.editMajorInfo(majorInfo);
		}
		return false;
	}
	
	public MajorInfoValue getMajorInfo() {
		return majorInfo;
	}

	public void setMajorInfo(MajorInfoValue majorInfo) {
		this.majorInfo = majorInfo;
	}

	public IMajorInfoDao getInfoDao() {
		return infoDao;
	}

	public void setInfoDao(IMajorInfoDao infoDao) {
		this.infoDao = infoDao;
	}

}
